#!/usr/bin/env python
from wsgiref.simple_server import make_server
import wsgiref.util
import time
import subprocess
import os
import threading

port = 8000

def server_app(environ, start_response):
	wsgiref.util.setup_testing_defaults(environ)
	status = '200 OK'
	headers = [('Content-type', 'application/json; charset=utf-8')]
	threading.Thread(target=update_git,args=(wsgiref.util.request_uri(environ),)).start()
	start_response(status, headers)
	#ret = [("%s: %s\n" % (key, value)).encode('utf-8')
     #      for key, value in environ.items()]
	return ['OK!\n'.encode('utf-8')]

def update_git(uri):
	#time.sleep(2)
	#os.chdir('/home/story/Desktop/test-git/temp-sample')
	#subprocess.run(['git', 'pull'])
	print('time-> %s ; path-> %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), uri), flush=True)

# httpd = make_server('', port, server_app)
# httpd.serve_forever()

with make_server('', port, server_app) as httpd:
	httpd.serve_forever()

